package com.pei.Dao.Impl;


import com.pei.Dao.regionDao;
import com.pei.entity.region;
import com.pei.util.BaseDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by dell on 2018/8/6.
 */
public class regionDaoImpl implements regionDao
{
    @Override
    public List<region> findregion(int areaId) {
        List<region> slist=new ArrayList<region>();
        Connection conn=null;
        PreparedStatement stat=null;
        ResultSet rs=null;
        String sql="select areaName from region where areaId=?";
        try {
            conn= BaseDao.getConnection();
            stat=conn.prepareStatement(sql);
            stat.setInt(1,areaId);
            rs=stat.executeQuery();
            while (rs.next()){
                region ut=new region();
                ut.setAreaName(rs.getString("areaName"));
                slist.add(ut);
            }
        }catch (Exception e){
            System.out.print(e.getMessage());
        }finally {
            BaseDao.closeConnection(conn,stat,rs);
        }
        return slist;
    }

    @Override
    public int findByIdregion(String name) {
        Connection conn=null;
        PreparedStatement stat=null;
        ResultSet rs=null;
        int num=0;
        String sql="select areaId from region where areaName=?";
        try {
            conn= BaseDao.getConnection();
            stat=conn.prepareStatement(sql);
            stat.setString(1,name);
            rs=stat.executeQuery();
            while (rs.next()){
                num=rs.getInt("areaId");
            }
        }catch (Exception e){
            System.out.print(e.getMessage());
        }finally {
            BaseDao.closeConnection(conn,stat,rs);
        }
        return num;
    }
}
